// settings.js
Page({
  data: {
    // 页面数据
    darkMode: false
  },

  onLoad: function (options) {
    // 页面加载时执行
    this.loadSettings();
    // 检查夜间模式设置
    this.checkDarkMode();
  },

  // 加载设置
  loadSettings: function () {
    const darkMode = wx.getStorageSync('darkMode') || false;
    this.setData({
      darkMode: darkMode
    });
  },

  // 检查夜间模式设置
  checkDarkMode: function () {
    const app = getApp();
    const darkMode = app.globalData.darkMode;
    this.setData({
      darkMode: darkMode
    });
  },

  // 夜间模式变化回调
  onDarkModeChange: function (darkMode) {
    this.setData({
      darkMode: darkMode
    });
  },

  // 切换夜间模式
  toggleDarkMode: function (e) {
    const darkMode = e.detail.value;
    this.setData({
      darkMode: darkMode
    });
    
    // 保存到本地存储
    wx.setStorageSync('darkMode', darkMode);
    
    // 通知应用切换夜间模式
    const app = getApp();
    if (app.toggleDarkMode) {
      app.toggleDarkMode(darkMode);
    }
    
    // 可以在这里添加切换主题的逻辑
    wx.showToast({
      title: darkMode ? '已开启夜间模式' : '已关闭夜间模式',
      icon: 'none'
    });
  }
});